import javax.swing.*;

/**
 * @classname 特效类
 * @Author 姬如千泷
 * @Date 2021/5/13  18:54
 * @Version 1.0
 */
public class MySpecial {
    public JLabel ll = new JLabel();//特效标签
    MyCharacter ct_label;//当前角色
    MyTown myTown;
    MyMap myMap;
    MyFrame myFrame;
    boolean where;
    public MySpecial(MyCharacter ct_label) {
        this.ct_label = ct_label;
        if(!ct_label.juage_where) {
            myTown = ct_label.bg_panel;
            myFrame = ct_label.myFrame;
        }else{
            myMap = ct_label.myMap;
        }
        where = ct_label.juage_where;
    }

    public void poised() {
        if(!where) myTown.add(ll,1);
        else myMap.add(ll,1);
        new Mypoised(0).start();
    }
    public void seam(){
        if(!where) myTown.add(ll,1);
        else myMap.add(ll,1);
        new MySeam(1).start();
    }
    public void crack(){
        if(!where) myTown.add(ll,1);
        else myMap.add(ll,1);
        new MyCrack(2).start();
    }
    class Mypoised extends Thread {//绘制蓄力特效
        int i;
        public Mypoised(int i) {
            this.i = i;
        }
        @Override
        public void run() {
            try {
                for (int i = 1; i < 7; i++) {
                    if (ct_label.juage_lr)
                        ll.setBounds(ct_label.ct_x - 45, ct_label.ct_y + 55, 50, 50);
                    else ll.setBounds(ct_label.ct_x + 90, ct_label.ct_y + 55, 50, 50);
                    ll.setIcon(juage(i - 1, this.i));
                    Thread.sleep(100);
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (ct_label.juage_lr)
                new Mybullet(ct_label.ct_x - 45, ct_label.ct_y + 30, ct_label, 1).start();
            else new Mybullet(ct_label.ct_x + 90, ct_label.ct_y + 30,  ct_label, 1).start();
            if(!where) {
                myTown.remove(ll);
                myTown.repaint();
            }else{
                myMap.remove(ll);
                myMap.repaint();
            }
        }
    }
    class MySeam extends Thread {//绘制鬼影闪裂缝特效
        int i;
        public MySeam(int i) {
            this.i = i;
        }
        @Override
        public void run() {
            try {
                for (int i = 1; i < 7; i++) {
                    if (ct_label.juage_lr)
                        ll.setBounds(ct_label.ct_x-400, ct_label.ct_y+20,700,150);
                    else ll.setBounds(ct_label.ct_x-250, ct_label.ct_y+20,700,150);
                    ll.setIcon(juage(i - 1,this.i));
                    Thread.sleep(100);
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if(!where) {
                myTown.remove(ll);
                myTown.repaint();
            }else{
                myMap.remove(ll);
                myMap.repaint();
            }
        }
    }
    class MyCrack extends Thread {//绘制圣灵斩击地缝特效
        int i;
        public MyCrack(int i) {
            this.i = i;
        }
        @Override
        public void run() {
            try {
                for (int i = 1; i < 7; i++) {
                    if (ct_label.juage_lr)
                        ll.setBounds(ct_label.ct_x-600, ct_label.ct_y+80,700,150);
                    else ll.setBounds(ct_label.ct_x, ct_label.ct_y+80,700,150);
                    ll.setIcon(juage(i - 1,this.i));
                    if(i==3) Thread.sleep(400);
                    Thread.sleep(100);
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if(!where) {
                myTown.remove(ll);
                myTown.repaint();
            }else{
                myMap.remove(ll);
                myMap.repaint();
            }
        }
    }
    public ImageIcon juage(int i, int t) {
        if (t == 0) {//绘制特效
            switch (i) {
                case 0:
                    return DateCenter.poised1;
                case 1:
                    return DateCenter.poised2;
                case 2:
                    return DateCenter.poised3;
                case 3:
                    return DateCenter.poised4;
                case 4:
                    return DateCenter.poised5;
                default:
                    return null;
            }
        } else if(t==1){
            switch (i) {
                case 0:
                    return DateCenter.seam1;
                case 1:
                    return DateCenter.seam2;
                case 2:
                    return DateCenter.seam3;
                case 3:
                    return DateCenter.seam4;
                case 4:
                    return DateCenter.seam5;
                case 5:
                    return DateCenter.seam6;
                default:
                    return null;
            }
        }else{
            switch (i) {
                case 0:
                    return DateCenter.crack1;
                case 1:
                    return DateCenter.crack2;
                case 2:
                    return DateCenter.crack3;
                case 3:
                    return DateCenter.crack4;
                case 4:
                    return DateCenter.crack5;
                default:
                    return null;
            }
        }
    }
}
